<template>
  <div class="container">
    <el-divider content-position="left"><span class="title-left-color">加盟信息</span></el-divider>
    <div style="margin: 0 70px">
      <el-descriptions :column="4" size="default">
        <el-descriptions-item label="姓名:">{{ form.name }}</el-descriptions-item>
        <el-descriptions-item label="联系电话:">{{ form.mobile }}</el-descriptions-item>
        <el-descriptions-item label="是否联系:">{{ form.is_contact }}</el-descriptions-item>
      </el-descriptions>
      <el-descriptions :column="2" size="default">
        <el-descriptions-item label="联系地址:">{{ form.city }}</el-descriptions-item>
      </el-descriptions>
      <el-descriptions :column="2" size="default">
        <el-descriptions-item label="用户备注信息:">{{ form.remark }}</el-descriptions-item>
      </el-descriptions>
    </div>
    <el-divider content-position="left"><span class="title-left-color">商务回访记录</span></el-divider>
    <div style="margin: 0 70px">
      <el-descriptions :column="2" size="default">
        <el-descriptions-item label="商务回访记录：">{{ form.platform_remark }}</el-descriptions-item>
      </el-descriptions>
    </div>

    <div class="footer-center">
      <el-button :disabled="disabledbtn" @click="cancelSubmit">取 消</el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import type { postOrPutType } from "@/constants";
import type { ViewMode } from "@/types/common";
import { useState } from "@/hooks/useState.ts";
import type { IInvestmentRecord } from "@/types/investmentRecord";
const { disabledbtn } = useState();
const form = defineModel<IInvestmentRecord>("form", { required: true });
const formStatus = defineModel<ViewMode>("formStatus", { required: true });
const emit = defineEmits<{
  handleInitData: [];
}>();

const isDisabledbtn = ref(false);
const methodType = ref<postOrPutType>("PUT");

onMounted(() => {
  console.log("Component mounted!");
});

/* formStatus处理器 */
const statusHandlers: Record<ViewMode, () => void> = {
  view: () => {
    isDisabledbtn.value = true;
  },
  edit: () => {
    methodType.value = "PUT";
  },
  add: () => {
    methodType.value = "POST";
  },
  none: () => {
    /* 初始化数据 */
    handleInitData();
  }
};
/* 监听formStatus,新增，编辑，查看的时候都可以打开模态框，又是有不同的操作和效果，需要单独判断，none为模态框关闭的情况，需要初始化数据 */
watch(formStatus, newValue => {
  const handler = statusHandlers[newValue];
  handler?.();
});

/* 初始化数据 */
function handleInitData() {
  methodType.value = "POST";
  isDisabledbtn.value = false;
}
/* 保存或编辑 取消提交 */
function cancelSubmit() {
  // clearData();
  // activeName = "one";
  emit("handleInitData");
}
</script>

<style lang="scss" scoped>
/* 修改select的盒模型 */
.el-select {
  display: block;
}
/* 底部按钮居中 */
.footer-center {
  margin: 10px 0;
  text-align: center;
}

.img-item {
  width: 100px;
  height: 100px;
  margin-right: 10px;
}
</style>
